package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

import model.dao.TestDAOImpl;
import model.vo.PagingBean;

/**
 * Servlet implementation class PNumberServlet
 */
public class PNumberServlet extends HttpServlet {
	
	private static final long serialVersionUID = 1L;
       
    
    public PNumberServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("servlet start");
		PagingBean pb=new PagingBean();
		int maxProduct;
		int nowPage;
		response.setContentType("text/html;charset=euc-kr");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		TestDAOImpl dao = new TestDAOImpl();
		nowPage=Integer.parseInt(request.getParameter("page"));
		try {
			
			maxProduct=dao.maxProduct();
			
			pb = new PagingBean(maxProduct,nowPage);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		JSONObject object = new JSONObject();
		
		object.put("pb",pb);
		out.print(object.toString());
	}

}
